package evolution.stop;

import evolution.algorithm.Iterative;

public class TimeStopCondition implements StopCondition<Iterative> {

	private int seconds;
	private boolean started = false;
	private long endTime;

	@Override
	public boolean shouldStop(Iterative algorithm) {
		if (!started) {
			endTime = System.currentTimeMillis() + seconds * 1_000;
			started = true;
		} else if (System.currentTimeMillis() > endTime) {
			return true;
		}
		return false;
	}

	@Override
	public int getParameter() {
		return seconds;
	}

	@Override
	public void setParameter(int parameter) {
		seconds = parameter;
	}
}
